package com.lm.csv.example;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;

import java.io.FileReader;

public class EnumFieldExample {
    enum Header {
        ID, Name, Age, Email
    }

    public static void main(String[] args) throws Exception {
        try (FileReader reader = new FileReader("e:\\csv\\output.csv");
             CSVParser parser = CSVFormat.DEFAULT
                     .withFirstRecordAsHeader()
                     .parse(reader)) {

            for (CSVRecord record : parser) {
                String id = record.get(Header.ID);
                String name = record.get(Header.Name);
                String age = record.get(Header.Age);
                String email = record.get(Header.Email);

                System.out.printf("ID: %s, Name: %s, Age: %s, Email: %s%n", id, name, age, email);
            }
        }
    }
}
